/*-----------------------------------------------------
 * File: boot.c
 *
 * Purpose:  Bootstrap handler, System solver
 *
 * Description:  
 * 
 * Version: 0.01 a0
 *             
 * Copyright 2001 ArSilicii srl
 *-----------------------------------------------------*/

#include  <stdio.h>
#include  <math.h>
#include "hal.h"        /* Include HAL definition */    
#include "ClkGen.h"     /* Include Oggetto: Clock generator */
#include "InParser.h"   /* Include Oggetto: Keyboard Input Event generator */
#include "OutDrv.h"     /* Include Oggetto: OutDrv */
#include "capture.h"    /* Include Oggetto: Capture */
#include "CU_Run.h"
#include "GUI_Run.h"

const struct tFLASHRAM NVRAM_Default={200l,250l,160l,32l};
       
void main(void)
{ 
  unsigned char fWormingUP;    
  HAL_init();
  fWormingUP=25;
  ClkGen_Init();
  InParser_Init();
  if(NVRAM.SogliaH==0xFFFF)HAL_NV_Write(NVRAM,NVRAM_Default); 
  Capture_Init();
  GUI_Run_Init();
  CU_Run_Init();
  
  LED.DL3=1;
  RELE.ReleCmd=0;
      
  while(1)          // Repeat forever
  {          
    if(ClkGen.n.Clk16m){    
       InParser_Clk();
       OutDrv_Clk();       
       if(fWormingUP) Capture_Init(); else  Capture_Clk();
    }    
    
    if(ClkGen.n.Clk128m){
       if((fWormingUP--)==0)fWormingUP=0;    
       InParser_Ack();
       
       CU_Run_Event.Start= (Capture_Status()!=0x00);
       //LED.DL3=CU_Run_Event.Start ;
       CU_Run_Clk();     
       
       GUI_Run_Event.Start= CU_Run_Event.Start;       
       RELE.ReleCmd= GUI_Run_Event.Alarm= CU_Run_Event.Alarm;       
       GUI_Run_Event.Run= CU_Run_Event.Run;
              
       GUI_Run_Clk();
       
    }
      
    if(ClkGen.n.Clk512m){      
      Capture_Calc_Freq();
    }
               
    ClkGen_Ack();
    
        
  }
}